#include "mypushbutton.h"
#include <QMouseEvent>
#include <QPainter>

MyPushButton::MyPushButton(QWidget *parent)
    : QPushButton{parent}
{}

void MyPushButton::Set_Image(const QString &normal, const QString &hover, const QString &pressed)
{
    normal_ = normal;
    hover_ = hover;
    pressed_ = pressed;
    pixmap_.load(normal_);
    update();
}

void MyPushButton::mousePressEvent(QMouseEvent *ev)
{
    if(ev->button() == Qt::LeftButton)
    {
        pixmap_.load(pressed_);
        update();
    }
    QPushButton::mousePressEvent(ev);
}

void MyPushButton::mouseReleaseEvent(QMouseEvent *ev)
{
    if(ev->button() == Qt::LeftButton)
    {
        pixmap_.load(normal_);
        update();
    }
    QPushButton::mouseReleaseEvent(ev);
}

void MyPushButton::enterEvent(QEvent *ev)
{
    pixmap_.load(hover_);
    update();
}

void MyPushButton::leaveEvent(QEvent *ev)
{
    pixmap_.load(normal_);
    update();
}

void MyPushButton::paintEvent(QPaintEvent *ev)
{
    QPainter draw(this);
    draw.drawPixmap(rect(),pixmap_);
}


